from sklearn.datasets import load_iris
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


iris = load_iris()
#x = iris.data
#y = iris.target


test_df = pd.DataFrame(iris.data, columns=iris.feature_names)
test_df['category'] = iris.target

print(test_df.info())
grouped = test_df.groupby('category')

plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
plt.hist(grouped['sepal length (cm)'].get_group(0),bins=10, alpha=0.5, color='b')
plt.hist(grouped['sepal length (cm)'].get_group(1),bins=10, alpha=0.5, color='r')
plt.hist(grouped['sepal length (cm)'].get_group(2),bins=10, alpha=0.5, color='g')


plt.subplot(1, 2, 2)
counts_0, bin_edges_0 = np.histogram(grouped['sepal length (cm)'].get_group(0), bins=30)
counts_1, bin_edges_1 = np.histogram(grouped['sepal length (cm)'].get_group(1), bins=30)
counts_2, bin_edges_2 = np.histogram(grouped['sepal length (cm)'].get_group(2), bins=30)
cdf_0 = np.cumsum(counts_0)
cdf_1 = np.cumsum(counts_1)
cdf_2 = np.cumsum(counts_2)
plt.plot(bin_edges_0[1:], cdf_0/len(grouped['sepal length (cm)'].get_group(0)),color='b')
plt.plot(bin_edges_1[1:], cdf_1/len(grouped['sepal length (cm)'].get_group(1)),color='r')
plt.plot(bin_edges_2[1:], cdf_2/len(grouped['sepal length (cm)'].get_group(2)),color='g')

plt.xlabel('Sepal Length')
plt.ylabel('CDF')
plt.legend(['Setosa', 'Versicolor', 'Virginica'])
plt.title('iris CDF')


plt.savefig('test_hist_numpy.png')

